//
//  DiDiDriverViewController.m
//  CarLife
//
//  Created by yu on 2017/11/20.
//  Copyright © 2017年 jpas. All rights reserved.
//

#import "DiDiDriverViewController.h"

@interface DiDiDriverViewController ()<UIWebViewDelegate>

@property (weak, nonatomic) IBOutlet UIWebView *webView;

@property (nonatomic, copy) NSString *URL;

@property (nonatomic, copy) NSString *currentURL;
@property (nonatomic) BOOL hasRemove;

@end

@implementation DiDiDriverViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"加载中...";
    [self setLeftImageNamed:@"back_gray" action:@selector(returnAction)];
    self.hasRemove = NO;
    
    NSString *URL = @"https://common.diditaxi.com.cn/general/webEntry#/";
//    NSString *URL = @"http://webapp.diditaxi.com.cn/?channel=55455";
    self.URL = URL;
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:URL]]];
}

- (void)returnAction
{
    if ([self.currentURL containsString:self.URL])
    {
        [self.navigationController popViewControllerAnimated:YES];
    } else {
        [self.webView goBack];
    }
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    NSString *currentURL = [webView stringByEvaluatingJavaScriptFromString:@"document.location.href"];
    self.currentURL = currentURL;
    NSString *navTitle = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
    
    PPLog(@"^^^^^ = %@****%@",currentURL,navTitle);
//    self.webView.request.URL.absoluteString
//    PPLog(@"&&&&& = %@",self.webView.request.URL.absoluteString);
//    self.currentURL = webView.request.URL.absoluteString;
    
    self.navigationItem.title = navTitle;
    
    [webView stringByEvaluatingJavaScriptFromString:@"var eles = document.getElementsByClassName('tab-item');\
     if(eles.length == 4){\
     document.getElementsByClassName('tab-item')[2].remove();\
     }"];
    
//    [self hideLoading];
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    
//    PPLog(@"&&& == %@",request.mainDocumentURL);
//    PPLog(@"@@@@ = %@",webView.request);
    return YES;
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
//    [self hideLoading];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self setWhiteNavigationBar];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self setDefaultNavigationBar];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
